/*
 * @Author: Clark
 * @Email: haixuanwoTxh@gmail.com
 * @Date: 2023-01-28 11:14:33
 * @LastEditors: Clark
 * @LastEditTime: 2023-01-28 11:23:27
 * @Description: file content
 */
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

void abort(void)
{
    sigset_t mask;
    struct sigaction action;

    // caller can't ignore SIGABRT, if so reset to default
    sigaction(SIGABRT, NULL, &action);
    if (SIG_IGN == action.sa_handler)
    {
        action.sa_handler = SIG_DFL;
        sigaction(SIGABRT, &action, NULL);
    }

    if (SIG_DFL == action.sa_handler)
        fflush(NULL);

    // Caller can't block SIGABRT; make sure it's unblock
    sigfillset(&mask);
    sigdelset(&mask, SIGABRT);  // mask has only SIGABRT turned off
    sigprocmask(SIG_SETMASK, &mask, NULL);
    kill(getpid(), SIGABRT);

    // if we're here, process caught SIGABRT and returned
    fflush(NULL);
    action.sa_handler = SIG_DFL;
    sigaction(SIGABRT, &action, NULL);      // reset to default
    sigprocmask(SIG_SETMASK, &mask, NULL);  // just in case ..
    kill(getpid(), SIGABRT);

    exit(1); // this should never be excuted ...
}
